﻿using System;
using System.Data;
using System.Data.SqlClient;


namespace IncubatorServices
{
    class sqlManager
    {

        SqlConnection conn;

        public sqlManager()
        {
            string connectionstring = "Data Source=localhost; Initial Catalog=incudb; User Id=sa; Password=incu";
            conn = new SqlConnection(connectionstring);


        }
        public DataSet GetDataSet(string sqlstring)
        {
            //SqlCommand cmd = new SqlCommand(sqlstring, conn);
            //reader = cmd.ExecuteReader();
            conn.Open();
            SqlDataAdapter da = new SqlDataAdapter(sqlstring, conn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            conn.Close();
            return ds;
        }
        public string GetScalar(string sqlstring)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sqlstring, conn);
            string s = cmd.ExecuteScalar().ToString();
            conn.Close();
            return s;
        }
        public int NonQuery(string sqlstring)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sqlstring, conn);
            int result = cmd.ExecuteNonQuery();
            conn.Close();
            return result;
        }
        public static string GetData(object data)
        {

            if (data is DBNull)
                return "";
            if (data is Int32)
                return data.ToString();
            if (data is string)
                return (string)data;
            return "";

        }
        public static int GetDataInt(object data)
        {
            return Int32.Parse(GetData(data));
        }

    }
}